package com.aaa.sbms.dao;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;
import java.util.Map;

public interface EmpCheckInDao {
    @Select("<script>select userid,username,sex,islock from users a " +
            " where state=0 and a.userid NOT in (select USERID from checkins)" +
            "<if test=\"userid!=null and userid!=''\"> and userid like concat('%',#{userid},'%') </if>" +
            "<if test=\"username!=null and username!=''\"> and username like concat('%',#{username},'%')  </if>" +
            "ORDER BY islock </script>")
    List<Map> list(Map map);

    //根据工号修改意向
    @Update("update users  set islock=1 where userid=#{userid}")
    Integer updateIng(Integer userid);

    //根据性别查询员工宿舍单元
    @Select("select FLOOR from houses where SEX=#{sex} group by FLOOR")
    List<Map> floorList(Map map);

    //根据性别和楼层查询楼层房间信息
    @Select("select ROOM from houses where BED!=0 and FLOOR=#{floor} AND SEX=#{sex} group by ROOM")
    List<Map> roomList(Map map);

    @Update("update houses set BED=BED-1 where SEX=#{sex} and FLOOR=#{floor} and ROOM=#{room}")
    int delBedCount(Map map);

    @Insert("<script> insert into checkins(USERID,USERNAME,SEX,FLOOR,ROOM,CHECKINDATE,HOUSEID) \n" +
            "VALUES(#{userid},#{username},#{sex},#{floor},#{room},NOW(),#{HOUSEID}" +
            ")</script>")
    int insert(Map map);
}
